import datetime

from django.db import models
from user.models import Users
import time
import random
from attractions.models import AttractionTicke

# Create your models here.

class Order(models.Model):
    statulist=[(0, '已取消'), (1, '未支付'), (2, '已支付'), (3, '待评价'), (4, '已完成')]
    ordernum = models.CharField(max_length=100, verbose_name='订单号', primary_key=True,
                                default='x' + str(time.time()) + str(random.randint(1000, 9999)))
    name = models.CharField(max_length=100)
    price = models.IntegerField(verbose_name='价格')
    status = models.IntegerField(default=1, verbose_name='状态',
                                 choices=statulist)
    ticket = models.ForeignKey(AttractionTicke, on_delete=models.CASCADE)
    usetime = models.DateTimeField(verbose_name='使用时间', default=datetime.datetime.now()+datetime.timedelta(days=1))
    num = models.IntegerField(verbose_name='购买数量')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    user = models.ForeignKey(Users, on_delete=models.CASCADE)
    isdelete = models.BooleanField(default=False, verbose_name='是否删除')

    class Meta:
        db_table = 'order'
